import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class auto {
    public WebDriver driver=null;
    public void start() {
        //打开浏览器
        WebDriverManager.chromedriver().setup();
        //添加浏览器配置
        ChromeOptions options = new ChromeOptions();
        //允许访问所有链接
        options.addArguments("--remote-allow-origins=*");
        driver = new ChromeDriver(options);
    }
    public void end() {
        //关闭浏览器
        driver.quit();
    }
    public void test1() throws InterruptedException {
        //定位 css
        //新闻
        driver.findElement(By.cssSelector("#s-top-left > a:nth-child(1)"));
        driver.findElement(By.cssSelector("#hotsearch-content-wrapper > li:nth-child(1) > a > span.title-content-title"));
        Thread.sleep(10000);

        //xpath
        driver.findElement(By.xpath("//*[@id=\"s-top-left\"]/a[1]"));
        driver.findElement(By.xpath("//*[@id=\"hotsearch-content-wrapper\"]/li[1]/a/span[2]"));
        Thread.sleep(10000);

        //查找不存在的元素
        driver.findElement(By.xpath("//*[@id=\"hotsearch-contentaaaaa-wrapper\"]/li[1]/a/span[2]"));
        Thread.sleep(10000);
        end();
    }
}
